package presentation.panels.modifierUser;

import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel;

import metier.entite.user.User;
import metier.exceptions.ChargerListException;
import metier.userService.UserService;


@SuppressWarnings("serial")
public class RecapitulatifsUsers extends AbstractTableModel {

	private final String[] entetes = { "Identifiant", "User Name", "Type","e-mail","Remove"};

	private UserService userService;
	
	private boolean onlyClient ;

	private List<User> listUsers = new ArrayList<User>();

	public RecapitulatifsUsers(UserService userService , boolean onlyClient) {
		super();
		this.userService = userService ;
		this.onlyClient = onlyClient ;
	}
	
	public void chargerListUser() throws ChargerListException {
		listUsers = (onlyClient==true) ? userService.chargerListUserClient() : userService.chargerListAllUsers() ;
		System.out.println("DEBUG -- REcp");
		for (User u : listUsers){
			System.out.println(u.toString());
		}
	}

	@Override
	public int getColumnCount() {
		return entetes.length;
	}

	@Override
	public String getColumnName(int columnIndex) {
		return entetes[columnIndex];
	}

	@Override
	public int getRowCount() {
		return listUsers.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex) {

		case 0:
			return listUsers.get(rowIndex).getId() ;
		case 1:
			return listUsers.get(rowIndex).getUserName();
		case 2:
			return listUsers.get(rowIndex).getType().toString();
		case 3:
			return "adresse email";
		case 4:
			return new ImageIcon() ;			
		default:
			throw new IllegalArgumentException();
		}
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		switch (columnIndex) {

		case 0:
			return Integer.class;
		case 1:
			return String.class;
		case 2:
			return String.class;
		case 3:
			return String.class;
		default:
			return Object.class;
		}
	}

	/**
	 * @return the onlyClient
	 */
	public boolean isOnlyClient() {
		return onlyClient;
	}

	/**
	 * @param onlyClient the onlyClient to set
	 */
	public void setOnlyClient(boolean onlyClient) {
		this.onlyClient = onlyClient;
	}

	/**
	 * @return the listUsers
	 */
	public List<User> getListUsers() {
		return listUsers;
	}

	/**
	 * @param listUsers the listUsers to set
	 */
	public void setListUsers(List<User> listUsers) {
		this.listUsers = listUsers;
	}


}
